<?php
/*
Plugin Name: WP_taoke
Plugin URI: http://www.7heart.com/
Description: 把文章中的淘客代码（图形形式）分解，存入自定义字段中，方便天和theme调用。
Version: 0.1
Author: LD King
Author URI: http://mifunny.info/
*/
/**
 * @file taoke9527.php
 * @package 7heart_taoke
 * @version $id: 0.1 UTF-8 2009-3-10 下午08:28:21 $
 * @author LD King (mifunny.info)
 * @copyright Copyright (c) 2007 - 2009 MiFunny China Inc. (http://mifunny.info)
 * 0.taoke_table 图形形式全部table代码
 * 1.taoke_url 推广链接
 * 2.taoke_image 图片
 * 3.taoke_title 文字
 * 4.taoke_price 价格
 */

class wp_taoke {
	
	function taoke_post_meta_tags($id) {
		global $content;
		$pattern = '/<table.+?<a.+?href=\\\"(.+?)\\\".+?<img.+?src=\\\"(.+?)\\\".+?<a.+?>(.+?)<\/a>.+?<span.+?>(.+?)<\/span>.+?<\/table>/s';
		$matches = array();
		
		if ( preg_match($pattern, $content, $matches, PREG_OFFSET_CAPTURE, 0) ) {
			$taoke_info = array(
				'taoke_table' => $matches[0][0],
				'taoke_url' => $matches[1][0],
				'taoke_image' => $matches[2][0],
				'taoke_title' => $matches[3][0],
				'taoke_price' => $matches[4][0]			
				);
	
			foreach ($taoke_info as $k => $v) {
				delete_post_meta($id, $k);
				add_post_meta($id, $k, $v, true) or update_post_meta($id, $k, $v);
			}
		} // have taoke code
	} //END func taoke_post_meta_tags
} //END class wp_taoke

$taoke = new wp_taoke();

add_action('edit_post', array(&$taoke, 'taoke_post_meta_tags'));
add_action('publish_post', array(&$taoke, 'taoke_post_meta_tags'));
add_action('save_post', array(&$taoke, 'taoke_post_meta_tags'));
add_action('edit_page_form', array(&$taoke, 'taoke_post_meta_tags'));
?>